package com.mayikt.mapper;


import com.mayikt.entity.UserDO;
import io.lettuce.core.dynamic.annotation.Param;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;


public interface UserMapper {

    @Insert("INSERT INTO `meite_user` VALUES (null, #{mobile},null, #{password}, null, '0', '0', now()," +
            " now(),'1',null , null, null);\n")
    int register(UserDO userDo);

    @Select("SELECT USER_ID AS USERID ,MOBILE AS MOBILE ,password as password\n" +
            ",user_name as username ,user_name as username,sex as sex \n" +
            ",age as age ,create_time as createtime,IS_AVAILABLE as isAvailable\n" +
            ",\n" +
            "pic_img  as picimg,qq_openid as qqopenid ,wx_openid as wxopenid\n" +
            "\n" +
            "from meite_user  where MOBILE=#{mobile}")
    UserDO login(String mobile, String passWord);

    @Select("SELECT USER_ID AS USERID ,MOBILE AS MOBILE ,password as password\n" +
            ",user_name as username ,user_name as username,sex as sex \n" +
            ",age as age ,create_time as createtime,IS_AVAILABLE as isAvailable\n" +
            ",\n" +
            "pic_img  as picimg,qq_openid as qqopenid ,wx_openid as wxopenid\n" +
            "\n" +
            "from meite_user  where MOBILE=#{mobile}")
    UserDO existMobile(String mobile);
    @Select("SELECT USER_ID AS USERID ,MOBILE AS MOBILE ,password as password\n" +
            ",user_name as username ,user_name as username,sex as sex \n" +
            ",age as age ,create_time as createtime,IS_AVAILABLE as isAvailable\n" +
            ",\n" +
            "pic_img  as picimg,qq_openid as qqopenid ,wx_openid as wxopenid\n" +
            "\n" +
            "from meite_user  where USER_ID=#{userId}")
    UserDO findByUser(Long userId);

    @Update("\n" +
            "update meite_user set WX_OPENID=#{wxOpenId}  where user_id=#{userId};")
    int updateUseOpenId(Long userId, String wxOpenId);

    @Select("SELECT USER_ID AS USERID ,MOBILE AS MOBILE ,password as password\n" +
            ",email as email ,user_name as username,sex as sex \n" +
            ",age as age ,create_time as createtime, IS_AVAILABLE as isAvailable\n" +
            ",\n" +
            "pic_img  as picImg,qq_openid as qqOpenId ,wx_openid as wxOpenId\n" +
            "\n" +
            "from meite_user  where wx_OpenId=#{wxOpenId}")
    UserDO selectByOpenId(String wxOpenId);

    @Select("SELECT USER_ID AS USERID ,MOBILE AS MOBILE ,password as password\n" +
            ",email as email ,user_name as username,sex as sex \n" +
            ",age as age ,create_time as createtime, IS_AVAILABLE as isAvailable\n" +
            ",\n" +
            "pic_img  as picImg,qq_openid as qqOpenId ,wx_openid as wxOpenId\n" +
            "\n" +
            "from meite_user where qq_OpenId=#{qqOpenId}")
    UserDO selectByQQOpenId(String qqOpenId);


    @Update("\n" +
            "update meite_user set WX_OPENID=null  where WX_OPENID=#{wxOpenId};")
    int cancelFollowOpenId(String wxOpenId);

    @Update("\n" +
            "update meite_user set qq_OPENID=#{qqOpenId}  where user_id=#{userId};")
    int updateUserOpenId(@Param("userId") Long userId, @Param("qqOpenId") String qqOpenId);

}
